Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: OpenDoc Cookbook /
Chapter 2 - SamplePart Tutorial


Shared Global Variables

In addition to the method and instance variables declared in Listing 2-1, SamplePart uses a set of global variables, declared as members of a C++ structure. These variables are shared among all the currently running instances of the SamplePart object in a single document. In addition, SamplePart maintains two separate global variables to provide access to the shared globals: a pointer to the global variables structure, and a count of the number of instances of the SamplePart class currently using the global variables.

The global variables are defined and initialized in the files SamplePartGlobals.h and SamplePartGlobals.cpp. The global variables structure is allocated in temporary memory by the Initialize method (see Listing 2-6).

The global variables structure definition is shown in Listing 2-2.

Listing 2-2 SamplePart global variables

struct SamplePartGlobals; // forward

extern ODUShort      gGlobalsUsageCount;
extern SamplePartGlobals* gGlobals;


struct SamplePartGlobals {
   public:
   SamplePartGlobals();
   ~SamplePartGlobals() {}
   
   ODMenuBar*     fMenuBar;
   ODFocusSet*    fUIFocusSet;
   Handle         fThumbnail;
            
   ODTypeToken    fSelectionFocus;
   ODTypeToken    fMenuFocus;
   ODTypeToken    fModalFocus;
   ODTypeToken    fFrameView;
   ODTypeToken    fLargeIconView;
   ODTypeToken    fSmallIconView;
   ODTypeToken    fThumbnailView;
   ODTypeToken    fMainPresentation;
         
   ODScriptCode   fEditorsScript;
   ODLangCode     fEditorsLanguage;
};

inline SamplePartGlobals::SamplePartGlobals()
{
   fMenuBar    = kODNULL;
   fUIFocusSet = kODNULL;
   fThumbnail  = kODNULL;
            
   fSelectionFocus   = kODNullTypeToken;
   fMenuFocus        = kODNullTypeToken;
   fModalFocus       = kODNullTypeToken;
   fFrameView        = kODNullTypeToken;
   fLargeIconView    = kODNullTypeToken;
   fSmallIconView    = kODNullTypeToken;
   fThumbnailView    = kODNullTypeToken;
   fMainPresentation = kODNullTypeToken;
         
   fEditorsScript = 0;
   fEditorsLanguage= 0;
}
ODUShort       gGlobalsUsageCount= 0;
SamplePartGlobals*gGlobals    = kODNULL;

Previous Book Contents Book Index Next

© Apple Computer, Inc.
16 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help